﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Kaskelot.Services.Model;

namespace Stockholm.SOA.Kaskelot.WCF.ServiceImplementation.Mapping
{
	public static class PersonTypExtensions
	{
		public static DataContracts.PersonTyp ToContract(this PersonTyp entity)
		{
			DataContracts.PersonTyp b = new DataContracts.PersonTyp();

			CopyFromEntity(entity, b, false);

			return b;
		}

		public static DataContracts.PersonTyp ToMinimalContract(this PersonTyp entity)
		{
			DataContracts.PersonTyp b = new DataContracts.PersonTyp();

			CopyFromEntity(entity, b, true);

			return b;
		}

		public static PersonTyp ToEntity(this DataContracts.PersonTyp b)
		{
			PersonTyp entity = new PersonTyp();

			CopyToEntity(b, entity);

			return entity;
		}

		public static void UpdateEntity(this PersonTyp entity, DataContracts.PersonTyp pt)
		{
			CopyToEntity(pt, entity);
		}

		private static void CopyFromEntity(PersonTyp from, DataContracts.PersonTyp to, bool minimal)
		{
			to.Id = from.Id;
			to.ValId = from.ValId;

			to.Namn = from.Benamning;

			to.Andrad = from.Andrad;
			to.AndradAv = from.AndradAv;
			to.Skapad = from.Skapad;
			to.SkapadAv = from.SkapadAv;
		}

		private static void CopyToEntity(DataContracts.PersonTyp from, PersonTyp to)
		{
			to.Id = from.Id;
			to.ValId = from.ValId;

			to.Benamning = from.Namn;

			to.Andrad = from.Andrad;
			to.AndradAv = from.AndradAv;
			to.Skapad = from.Skapad;
			to.SkapadAv = from.SkapadAv;
		}
	}
}
